<style scoped>
  .clientAccountCheck{
    margin-right: 0.5vw;
    padding: 0 15px;
    background-color: white;
    height: 95vh;
    position: relative;
  }
  .cr-top{
    display: flex;
    padding: 1.5vh 0;
    border-bottom: 2px solid #f4f4f4;
  }
  .cr-top p:first-child{
    margin: 3px 6px 0 0;
  }
  .cr-top p:not(:first-child){
    margin: 3px 6px 0 12px;
  }
  .cr-button{
    padding: 1.5vh 0;
  }
  .cr-tab{
    display: flex;
  }
  #tab-left{
    width: 52%;
    padding-right: 0.5%;
    border-right: 2px solid #f4f4f4;
    height: 75.5vh;
    overflow-y: auto;
  }
  .tab-right{
    width: 48%;
    padding-left: 1%;
  }
  .tab-right div:first-child{
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 1vh
  }
  .jl{
    font-size: 15px;
    font-weight: 600;
    line-height: 4vh;
    text-align: center;
  }
  .tab-bottom{
    display: flex;
    justify-content: space-between;
  }
  .tab-bottom>div{
    display: flex;
    font-weight: normal;
    margin: 1.5vh 0;
  }
  .footView span{
    float: left;
    margin-right: 48px;
    line-height: 6vh;
    font-size: 14px;
  }
</style>

<style>
  .clientAccountCheck .el-input__icon {
    line-height: 30px;
  }
  .clientAccountCheck .cr-top .el-input__inner{
    height: 30px;
  }
  .clientAccountCheck .cr-top .el-date-editor .el-range-separator{
    width: 8%;
    line-height: 23px;
  }
  .clientAccountCheck .cr-top .el-date-editor .el-range__icon{
    line-height: 23px;
  }
  .clientAccountCheck .cr-top .el-date-editor.el-input__inner{
    width: 350px;
  }
  .clientAccountCheck #table5 .cell{
    padding: 0;
  }
  .clientAccountCheck #tab-left .cell {
    padding: 0;
  }
</style>

<template>
  <div class="clientAccountCheck">
    <div class="cr-top">
      <p>客户</p>
      <!-- <el-input style="width:60px;margin-right:10px;" v-model="customerNo" @blur="customerNoBlur" :disabled="jxAgent"></el-input> -->
      <el-select v-model="customerName" filterable
                 @change="e=>{this.customerNo=e;this.customerNoBlur()}" 
                 style="width:160px" 
                 :disabled="jxAgent">
        <el-option v-for="item in customerList" 
          :key="item.value" 
          :label="item.value + ' ' + item.label" 
          :value="item.value">
        </el-option>
      </el-select>
      <p>总店编号</p>
      <el-input style="width:160px;" v-model="headquartersNo"></el-input>
      <p>日期</p>
      <el-date-picker
        unlink-panels 
        v-model="dateList" 
        type="daterange" 
        range-separator="至" 
        start-placeholder="开始日期" 
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd"></el-date-picker>
    </div>

    <div class="cr-button">
      <el-button @click="search" type="primary" icon="el-icon-search">查询</el-button>
      <el-button @click="exportExcel" icon="el-icon-upload2">导出</el-button>
      <el-button @click="printClick" icon="el-icon-printer">列印</el-button>
    </div>

    <div class="cr-tab">
      <div id="tab-left">
        <div class="jl">
          <p>代销应收明细</p>
          <!-- <p>{{customerName}}（{{customerNo}}）客户对账单（{{dateList ? dateList[0] : ''}} 至 {{dateList ? dateList[1] : ''}}）</p> -->
        </div>
        <el-table 
          :data="tableData1" 
          style="width: 100%" 
          :header-cell-style="{background:'#f4f4f4',padding:0,height:'40px'}" 
          :cell-style="{padding:0,height:'36px'}"
          show-summary 
          :summary-method="getSummaries">
          <el-table-column type="index" label="序号" width="40"></el-table-column>
          <el-table-column prop="enteringTime" label="销货日期" width="90"></el-table-column>
          <el-table-column prop="styleNumber" label="款号" min-width="100"></el-table-column>
          <el-table-column prop="color" label="颜色" min-width="80"></el-table-column>
          <el-table-column prop="size" label="尺码" width="50"></el-table-column>
          <el-table-column prop="number" label="数量" width="40"></el-table-column>
          <el-table-column prop="sellingPrice" label="售价" width="70"></el-table-column>
          <el-table-column prop="commodityName" label="品名" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column prop="brandedName" label="品牌" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column prop="money" label="售价金额" min-width="80"></el-table-column>
          <el-table-column prop="discount" label="折数" width="40"></el-table-column>
          <el-table-column prop="onePrice" label="单价" min-width="70"></el-table-column>
          <el-table-column prop="officialReceipts" label="实收" min-width="80"></el-table-column>
        </el-table>
        <div class="jl">
          <p>进退单据明细</p>
        </div>
        <div style="display:flex;width:100%;">
          <el-table 
            :data="tableData2" 
            ref="table2"
            show-summary 
            style="width: 100%" 
            :header-cell-style="{background:'#f4f4f4',padding:0,height:'40px'}" 
            :cell-style="{padding:0,height:'36px'}"
            highlight-current-row
            @row-click="rowClick2">
            <el-table-column type="index" label="序号" width="40"></el-table-column>
            <el-table-column prop="purchaseTime" label="进货日期" width="90"></el-table-column>
            <el-table-column prop="inputSequence" label="进货序号" width="110"></el-table-column>
            <el-table-column prop="type" label="类型" min-width="70" show-overflow-tooltip></el-table-column>
            <el-table-column prop="number" label="数量" width="40"></el-table-column>
            <el-table-column prop="money" label="金额" min-width="60"></el-table-column>
          </el-table>
          <el-table 
            :data="tableData3" 
            ref="table3"
            style="width: 100%" 
            show-summary 
            :header-cell-style="{background:'#f4f4f4',padding:0,height:'40px'}" 
            :cell-style="{padding:0,height:'36px'}"
            highlight-current-row
            @row-click="rowClick3">
            <el-table-column type="index" label="序号" width="40"></el-table-column>
            <el-table-column prop="outTime" label="退货日期" width="90"></el-table-column>
            <el-table-column prop="outSequence" label="退货序号" width="110"></el-table-column>
            <el-table-column prop="type" label="类型" min-width="70" show-overflow-tooltip></el-table-column>
            <el-table-column prop="number" label="数量" width="40"></el-table-column>
            <el-table-column prop="money" label="金额" min-width="60"></el-table-column>
          </el-table>
        </div>
        <div class="jl">
          <p>进退销存</p>
        </div>
        <div>
          <el-table 
            :data="tableData4" 
            style="width: 100%" 
            :header-cell-style="{background:'#f4f4f4',padding:0,height:'40px'}" 
            :cell-style="{padding:0,height:'36px'}"
            height="76">
            <el-table-column prop="topInventory" label="上存"  min-width="60"></el-table-column>
            <el-table-column prop="thisInput" label="本进"  min-width="60"></el-table-column>
            <el-table-column prop="thisOut" label="本退"  min-width="60"></el-table-column>
            <el-table-column prop="thisSell" label="本销"  min-width="60"></el-table-column>
            <el-table-column prop="thisInventory" label="本存"  min-width="60"></el-table-column>
            <el-table-column prop="topInventoryMoney" label="上存金额"></el-table-column>
            <el-table-column prop="thisInputMoney" label="本进金额"></el-table-column>
            <el-table-column prop="thisOutMoney" label="本退金额"></el-table-column>
            <el-table-column prop="thisSellMoney" label="本销金额"></el-table-column>
            <el-table-column prop="inventoryMoney" label="客存金额"></el-table-column>
          </el-table>
        </div>
        <div class="tab-bottom">
          <div>
            <p>制表人员：{{operator}}</p>
            <span style="width:30px"></span>
            <p>制表日期：{{today}}</p>
          </div>
          <div>
            <p>{{companyName}}</p>
          </div>
        </div>
      </div>
      <div class="tab-right">
        <div>
          <p>{{detail}}货明细</p>
        </div>
        <el-table 
          :data="tableData5" 
          style="width: 100%" 
          id="table5"
          ref="table5"
          :header-cell-style="{background:'#f4f4f4',padding:0,height:'40px'}" 
          :cell-style="{padding:0,height:'36px'}"
          height="72vh"
          show-summary>
          <el-table-column prop="typeNumber_colorNo" label="款号-色号" min-width="120"></el-table-column>
          <el-table-column prop="colorName" label="颜色" min-width="60"></el-table-column>
          <el-table-column prop="c05" label="C05" min-width="40"></el-table-column>
          <el-table-column prop="c07" label="C07" min-width="40"></el-table-column>
          <el-table-column prop="c09" label="C09" min-width="40"></el-table-column>
          <el-table-column prop="c11" label="C11" min-width="40"></el-table-column>
          <el-table-column prop="c13" label="C13" min-width="40"></el-table-column>
          <el-table-column prop="c15" label="C15" min-width="40"></el-table-column>
          <el-table-column prop="c17" label="C17" min-width="40"></el-table-column>
          <el-table-column prop="c19" label="C19" min-width="40"></el-table-column>
          <el-table-column prop="c21" label="C21" min-width="40"></el-table-column>
          <el-table-column prop="c23" label="C23" min-width="40"></el-table-column>
          <el-table-column prop="f" label="F" min-width="40"></el-table-column>
          <el-table-column prop="total" label="小计" min-width="50"></el-table-column>
          <el-table-column prop="onePrice" label="单价" min-width="50"></el-table-column>
          <el-table-column prop="money" label="金额" min-width="50"></el-table-column>
        </el-table>
      </div>
    </div>
    <foot-view class="footView">
      <div slot="text">
        <span>数据库：{{jxQuarter}}</span>
      </div>
    </foot-view>
    <div v-show=false id="p"></div>
  </div>
</template>

<script>
const resources = require('../../../config/printCSS5')

import { getClient, customerAccounts } from '../../../network/client'
import { getSystemConfig } from '../../../network/operatoryCommand'

import footView from '../../../components/FootView'

import XLSX from "xlsx"
import FileSaver from "file-saver"

import today from '../../../components/mixins/today'
import enterUp from '../../../components/mixins/enterUp'

export default {
  name:'client_account_check',
  mixins: [today,enterUp],
  data(){
    return{
      inpList: [],
      jxQuarter: null,
      jxAgent:null,
      operator:null,
      // operator: document.cookie.match(RegExp('jxUser'+'=([^;]+)'))[1],
      // jxQuarter: document.cookie.match(RegExp('jxQuarter'+'=([^;]+)'))[1],
      // jxAgent: document.cookie.match(RegExp('jxAgent'+'=([^;]+)'))[1] == 1 ? true : false,
      today: this.searchDate(),

      customerNo: '',
      customerName: '',
      customerList: [],
      headquartersNo: '',
      dateList: null,
      tableData1: [],
      tableData2: [],
      tableData3: [],
      tableData4: [],
      tableData5: [],

      customerInputInfoTwoMap: {},
      customerOutInfoTwoMap: {},

      companyName: '',
      detail: '进',

      sums: null
    }
  },
  watch: {
    customerNo(a,b){
      this.customerNo = a.toUpperCase().trim()
    },
    headquartersNo(a,b){
      this.headquartersNo = a.toUpperCase().trim()
    }
  },
  components:{
    footView
  },
  methods: {
    search(){
      if (!this.customerNo) {
        this.$message.info('请选择客户')
        return
      }
      let params = {
        customerNo: this.customerNo,
        headquartersNo: this.headquartersNo,
        startTime: this.dateList ? this.dateList[0] + ' 00:00:00' : '',
        endTime: this.dateList ? this.dateList[1] + ' 23:59:59' : ''
      }
      customerAccounts(params).then(res => {
        // console.log(res)
        this.tableData1 = []
        this.tableData2 = []
        this.tableData3 = []
        this.tableData4 = []
        this.tableData5 = []
        if (res.data.code == 200) {
          let obj = res.data.data.customerAccountsTwoVO
          for (const key in obj) {
            if (Object.hasOwnProperty.call(obj, key)) {
              const element = obj[key]
              if (!element) obj[key] = ''
            }
          }
          this.tableData1 = res.data.data.customerAccountsOneVOList
          this.tableData2 = res.data.data.customerInputTotalList
          this.tableData3 = res.data.data.customerOutTotalList
          this.tableData4 = [obj]

          this.customerInputInfoTwoMap = res.data.data.customerInputInfoTwoMap
          this.customerOutInfoTwoMap = res.data.data.customerOutInfoTwoMap
        
          this.tableData1.forEach(e => {
            e.enteringTime = e.enteringTime.slice(0,10)
            e.color = e.colorNo + '.' + e.colorName
          })
          this.tableData2.forEach(e => {
            e.purchaseTime = e.purchaseTime.slice(0,10)
            e.type = e.cooperateWay + '.' + e.customerNo
          })
          this.tableData3.forEach(e => {
            e.outTime = e.outTime.slice(0,10)
            e.type = e.cooperateWay + '.' + e.customerNo
          })

          for (const key in this.customerInputInfoTwoMap) {
            if (this.customerInputInfoTwoMap.hasOwnProperty(key)) {
              const f = this.customerInputInfoTwoMap[key]
              f.forEach(e => {
                e.total = e.c05 + e.c07 + e.c09 + e.c11 + e.c13 + e.c15 + e.c17 + e.c19 + e.c21 + e.c23 + e.f
                e.typeNumber_colorNo = e.typeNumber + '-' + e.colorNo
              })
            }
          }
          for (const key in this.customerOutInfoTwoMap) {
            if (this.customerOutInfoTwoMap.hasOwnProperty(key)) {
              const f = this.customerOutInfoTwoMap[key]
              f.forEach(e => {
                e.total = e.c05 + e.c07 + e.c09 + e.c11 + e.c13 + e.c15 + e.c17 + e.c19 + e.c21 + e.c23 + e.f
                e.typeNumber_colorNo = e.typeNumber + '-' + e.colorNo
              })
            }
          }
        }
      })
    },
    // 导出
    exportExcel(){
      // console.log(this.sums)
      let dataStr = ''
      if (this.dateList) {
        dataStr = `(${this.dateList[0]}至${this.dateList[1]})`
      }
      let header = {
        A1: {v: `${this.customerName}(${this.customerNo})客户对账单${dataStr}`},
        A2: {v: '序号'},
        B2: {v: '销货日期'},
        C2: {v: '款号'},
        D2: {v: '颜色'},
        E2: {v: '尺码'},
        F2: {v: '数量'},
        G2: {v: '售价'},
        H2: {v: '品名'},
        I2: {v: '售价金额'},
        J2: {v: '折数'},
        K2: {v: '单价'},
        L2: {v: '实收'}
      }
      //表格数据
      let data = {}
      let index = 3

      let sum1 = 0
      let sum2 = 0
      let sum3 = 0

      let sum4 = 0
      let sum5 = 0

      let sum6 = 0
      let sum7 = 0
      this.tableData1.forEach(e => {
        data['A' + index] = {v: index - 2}
        data['B' + index] = {v: e.enteringTime}
        data['C' + index] = {v: e.styleNumber}
        data['D' + index] = {v: e.color}
        data['E' + index] = {v: e.size}
        data['F' + index] = {v: e.number}
        data['G' + index] = {v: e.sellingPrice}
        data['H' + index] = {v: e.commodityName}
        data['I' + index] = {v: e.money}
        data['J' + index] = {v: e.discount}
        data['K' + index] = {v: e.onePrice}
        data['L' + index] = {v: e.officialReceipts}
        index++

        sum1 += e.number
        sum2 += e.money
        sum3 += e.officialReceipts
      })
      data['D' + index] = {v: '合计：'}
      data['F' + index] = {v: sum1}
      data['H' + index] = {v: '售价金额：'}
      data['I' + index] = {v: sum2}
      data['J' + index] = {v: '本期销售应收：'}
      data['L' + index] = {v: sum3}
      index++

      let merge1 = index - 1
      data['A' + index] = {v: '以上为：代销应收明细'}
      index++

      let merge2 = index - 1
      data['A' + index] = {v: '以下为：进退单据明细'}
      index++

      data['A' + index] = {v: '序号'}
      data['B' + index] = {v: '进货日期'}
      data['C' + index] = {v: '进货序号'}
      data['D' + index] = {v: '类型'}
      data['E' + index] = {v: '数量'}
      data['F' + index] = {v: '金额'}
      data['G' + index] = {v: '序号'}
      data['H' + index] = {v: '退货日期'}
      data['I' + index] = {v: '退货序号'}
      data['J' + index] = {v: '类型'}
      data['K' + index] = {v: '数量'}
      data['L' + index] = {v: '金额'}
      index++
      if (this.tableData2.length >= this.tableData3.length) {
        this.tableData2.forEach((e,i) => {
          data['A' + index] = {v: i + 1}
          data['B' + index] = {v: e.purchaseTime}
          data['C' + index] = {v: e.inputSequence}
          data['D' + index] = {v: e.type}
          data['E' + index] = {v: e.number}
          data['F' + index] = {v: e.money}

          sum4 += e.number
          sum5 += e.money
          
          if (this.tableData3[i]) {
            let f = this.tableData3[i]
            data['G' + index] = {v: i + 1}
            data['H' + index] = {v: f.outTime}
            data['I' + index] = {v: f.outSequence}
            data['J' + index] = {v: f.type}
            data['K' + index] = {v: f.number}
            data['L' + index] = {v: f.money}

            sum6 += e.number
            sum7 += e.money
          }
          index++
        })
      } else {
        this.tableData3.forEach((e,i) => {
          if (this.tableData2[i]) {
            let f = this.tableData2[i]
            data['A' + index] = {v: i + 1}
            data['B' + index] = {v: f.purchaseTime}
            data['C' + index] = {v: f.inputSequence}
            data['D' + index] = {v: f.type}
            data['E' + index] = {v: f.number}
            data['F' + index] = {v: f.money}

            sum4 += e.number
            sum5 += e.money
          }
          data['G' + index] = {v: i + 1}
          data['H' + index] = {v: e.outTime}
          data['I' + index] = {v: e.outSequence}
          data['J' + index] = {v: e.type}
          data['K' + index] = {v: e.number}
          data['L' + index] = {v: e.money}
          index++

          sum6 += e.number
          sum7 += e.money
        })
      }

      data['D' + index] = {v: '合计：'}
      data['E' + index] = {v: sum4}
      data['F' + index] = {v: sum5}
      data['J' + index] = {v: '合计：'}
      data['K' + index] = {v: sum6}
      data['L' + index] = {v: sum7}
      index++

      let merge3 = index - 1
      data['A' + index] = {v: '进退销存'}
      index++

      data['A' + index] = {v: '上存'}
      data['B' + index] = {v: '本进'}
      data['C' + index] = {v: '本退'}
      data['D' + index] = {v: '本销'}
      data['E' + index] = {v: '本存'}
      data['F' + index] = {v: '上存金额'}
      data['G' + index] = {v: '本进金额'}
      data['H' + index] = {v: '本退金额'}
      data['I' + index] = {v: '本销金额'}
      data['J' + index] = {v: '库存金额'}
      index++
      let d = this.tableData4[0]
      data['A' + index] = {v: d.topInventory}
      data['B' + index] = {v: d.thisInput}
      data['C' + index] = {v: d.thisOut}
      data['D' + index] = {v: d.thisSell}
      data['E' + index] = {v: d.thisInventory}
      data['F' + index] = {v: d.topInventoryMoney}
      data['G' + index] = {v: d.thisInputMoney}
      data['H' + index] = {v: d.thisOutMoney}
      data['I' + index] = {v: d.thisSellMoney}
      data['J' + index] = {v: d.inventoryMoney}
      index++

      data['H' + index] = {v: this.companyName}
      index++

      data['B' + index] = {v: '制表人：'}
      data['C' + index] = {v: this.operator}
      data['H' + index] = {v: '制表日期：'}
      data['I' + index] = {v: this.today}
      index++

      data['H' + index] = {v: '请核对无误后尽快安排汇款，谢谢！'}

      // 合并 headers 和 data
      let output = Object.assign({}, header, data);
      // 表格范围，范围越大生成越慢 
      let l = 0
      if (this.tableData2.length > this.tableData3.length) {
        l = this.tableData1.length + this.tableData2.length
      } else {
        l = this.tableData1.length + this.tableData1.length
      }
      
      let ref = 'A1:L' + (l + 10)
      //合并单元格设置
      let merges = [
        { s: { c: 0, r: 0 }, e: { c: 11, r: 0 } },
        { s: { c: 0, r: merge1 }, e: { c: 11, r: merge1 } },
        { s: { c: 0, r: merge2 }, e: { c: 11, r: merge2 } },
        { s: { c: 0, r: merge3 }, e: { c: 11, r: merge3 } }
      ]
      // 构建 workbook 对象
      let wb = {
        SheetNames: ['sheets1'],
        Sheets: {
          'sheets1': Object.assign({}, output, { '!ref': ref, '!merges': merges })
        }
      }
      
      // 导出 Excel
      XLSX.writeFile(wb, '销售明细与进退汇总表.xlsx')
    },
    // 客户编号失去焦点
    customerNoBlur(){
      if (this.customerNo != '') {
        for (const i of this.customerList) {
          if (this.customerNo == i.value) {
            this.customerName = i.label
            return
          }
        }
        this.$alert('无此客户编号', '', {
          confirmButtonText: '确定'
        })
        this.customerNo = ''
        this.customerName = ''
      } else {
        this.customerName = ''
      }
    },
    rowClick2(row){
      this.detail = '进'
      this.$refs.table3.setCurrentRow({})
      this.tableData5 = this.customerInputInfoTwoMap[row.inputSequence]
      this.tableData5.forEach(e => {
        for (const key in e) {
          if (Object.hasOwnProperty.call(e, key)) {
            const element = e[key];
            if (!element) e[key] = ''
          }
        }
      })
      this.$nextTick(() => {
        this.$refs.table5.doLayout()
      })
    },
    rowClick3(row){
      this.detail = '退'
      this.$refs.table2.setCurrentRow({})
      this.tableData5 = this.customerOutInfoTwoMap[row.outSequence]
      this.tableData5.forEach(e => {
        for (const key in e) {
          if (Object.hasOwnProperty.call(e, key)) {
            const element = e[key];
            if (!element) e[key] = ''
          }
        }
      })
    },

    printClick(){
      if (!this.tableData4.length) return
      document.getElementById('p').innerHTML = ''
      this.openPrint(1)
    },
    openPrint(n){
      // console.log('openPrint', n)
      let printBody = document.getElementById('p')
      let printTable = document.createElement('table')
      let dataStr = ''
      if (this.dateList) {
        dataStr = `(${this.dateList[0]}至${this.dateList[1]})`
      }
      let customerTitle = ''
      if (this.customerNo) {
        customerTitle = `${this.customerName}(${this.customerNo})`
      }
      printTable.innerHTML = `
        <tr>
          <td>${customerTitle}客户对账单${dataStr}</td>
        </tr>
        <tr>
          <td>序号</td>
          <td>销货日期</td>
          <td>款号</td>
          <td>颜色</td>
          <td>尺码</td>
          <td>数量</td>
          <td>售价</td>
          <td>品名</td>
          <td>售价金额</td>
          <td>折数</td>
          <td>单价</td>
          <td>实收</td>
        </tr>
      `
      let row = {}
      let index = 0
      this.tableData1.forEach(e => {
        row = printTable.insertRow(printTable.FetchRowCount)
        row.insertCell(0).innerHTML = index+1
        row.insertCell(1).innerHTML = e.enteringTime.slice(0,10)
        row.insertCell(2).innerHTML = e.styleNumber
        row.insertCell(3).innerHTML = e.color
        row.insertCell(4).innerHTML = e.size
        row.insertCell(5).innerHTML = e.number
        row.insertCell(6).innerHTML = e.sellingPrice
        row.insertCell(7).innerHTML = e.commodityName
        row.insertCell(8).innerHTML = e.money
        row.insertCell(9).innerHTML = e.discount
        row.insertCell(10).innerHTML = e.onePrice
        row.insertCell(11).innerHTML = e.officialReceipts
        index++
      })

      row = printTable.insertRow(printTable.FetchRowCount)
      row.insertCell(0).innerHTML = '以上为：代销应收明细'
      row = printTable.insertRow(printTable.FetchRowCount)
      row.insertCell(0).innerHTML = '以下为：进退单据明细'

      row = printTable.insertRow(printTable.FetchRowCount)
      row.insertCell(0).innerHTML = '序号'
      row.insertCell(1).innerHTML = '进货日期'
      row.insertCell(2).innerHTML = '进货序号'
      row.insertCell(3).innerHTML = '类型'
      row.insertCell(4).innerHTML = '数量'
      row.insertCell(5).innerHTML = '金额'
      row.insertCell(6).innerHTML = '序号'
      row.insertCell(7).innerHTML = '退货日期'
      row.insertCell(8).innerHTML = '退货序号'
      row.insertCell(9).innerHTML = '类型'
      row.insertCell(10).innerHTML = '数量'
      row.insertCell(11).innerHTML = '金额'

      let index1 = 1
      if (this.tableData2.length >= this.tableData3.length) {
        this.tableData2.forEach((e,j) => {
          row = printTable.insertRow(printTable.FetchRowCount)
          row.insertCell(0).innerHTML = j + 1
          row.insertCell(1).innerHTML = e.purchaseTime.slice(0,10)
          row.insertCell(2).innerHTML = e.inputSequence
          row.insertCell(3).innerHTML = e.type
          row.insertCell(4).innerHTML = e.number
          row.insertCell(5).innerHTML = e.money

          if (this.tableData3[j]) {
            let f = this.tableData3[j]
            row.insertCell(6).innerHTML = j + 1
            row.insertCell(7).innerHTML = f.outTime.slice(0,10)
            row.insertCell(8).innerHTML = f.outSequence
            row.insertCell(9).innerHTML = f.type
            row.insertCell(10).innerHTML = f.number
            row.insertCell(11).innerHTML = f.money
          } else {
            row.insertCell(6).innerHTML = ''
            row.insertCell(7).innerHTML = ''
            row.insertCell(8).innerHTML = ''
            row.insertCell(9).innerHTML = ''
            row.insertCell(10).innerHTML = ''
            row.insertCell(11).innerHTML = ''
          }
          index1++
        })
      } else {
        this.tableData3.forEach((e,j) => {
          row = printTable.insertRow(printTable.FetchRowCount)
          if (this.tableData2[j]) {
            let f = this.tableData2[j]
            row.insertCell(0).innerHTML = j + 1
            row.insertCell(1).innerHTML = f.purchaseTime.slice(0,10)
            row.insertCell(2).innerHTML = f.inputSequence
            row.insertCell(3).innerHTML = f.type
            row.insertCell(4).innerHTML = f.number
            row.insertCell(5).innerHTML = f.money
          } else {
            row.insertCell(0).innerHTML = ''
            row.insertCell(1).innerHTML = ''
            row.insertCell(2).innerHTML = ''
            row.insertCell(3).innerHTML = ''
            row.insertCell(4).innerHTML = ''
            row.insertCell(5).innerHTML = ''
          }

          row.insertCell(6).innerHTML = j + 1
          row.insertCell(7).innerHTML = e.outTime.slice(0,10)
          row.insertCell(8).innerHTML = e.outSequence
          row.insertCell(9).innerHTML = e.type
          row.insertCell(10).innerHTML = e.number
          row.insertCell(11).innerHTML = e.money
          
          index1++
        })
      }

      row = printTable.insertRow(printTable.FetchRowCount)
      row.insertCell(0).innerHTML = '进退销存'

      row = printTable.insertRow(printTable.FetchRowCount)
      row.insertCell(0).innerHTML = '上存'
      row.insertCell(1).innerHTML = this.tableData4[0].topInventory
      row.insertCell(2).innerHTML = '本进'
      row.insertCell(3).innerHTML = this.tableData4[0].thisInput
      row.insertCell(4).innerHTML = '本退'
      row.insertCell(5).innerHTML = this.tableData4[0].thisOut
      row.insertCell(6).innerHTML = '本销'
      row.insertCell(7).innerHTML = this.tableData4[0].thisSell
      row.insertCell(8).innerHTML = '本存'
      row.insertCell(9).innerHTML = this.tableData4[0].thisInventory
      // row.insertCell(10).innerHTML = '盘差'
      // row.insertCell(11).innerHTML = this.tableData4[0].pc
      row.insertCell(10).innerHTML = ''
      row.insertCell(11).innerHTML = ''

      row = printTable.insertRow(printTable.FetchRowCount)
      row.insertCell(0).innerHTML = '金额'
      row.insertCell(1).innerHTML = this.tableData4[0].topInventoryMoney
      row.insertCell(2).innerHTML = '本进金额'
      row.insertCell(3).innerHTML = this.tableData4[0].thisInputMoney
      row.insertCell(4).innerHTML = '本退金额'
      row.insertCell(5).innerHTML = this.tableData4[0].thisOutMoney
      row.insertCell(6).innerHTML = '本销金额'
      row.insertCell(7).innerHTML = this.tableData4[0].thisSellMoney
      row.insertCell(8).innerHTML = '库存金额'
      row.insertCell(9).innerHTML = this.tableData4[0].inventoryMoney
      // row.insertCell(10).innerHTML = '盘差金额'
      // row.insertCell(11).innerHTML = this.tableData4[0].pc
      row.insertCell(10).innerHTML = ''
      row.insertCell(11).innerHTML = ''

      row = printTable.insertRow(printTable.FetchRowCount)
      row.insertCell(0).innerHTML = ''
      row.insertCell(1).innerHTML = this.companyName || '公司'

      row = printTable.insertRow(printTable.FetchRowCount)
      row.insertCell(0).innerHTML = `制表人：${this.operator}`
      row.insertCell(1).innerHTML = `制表日期：${this.today}`

      row = printTable.insertRow(printTable.FetchRowCount)
      row.insertCell(0).innerHTML = ''
      row.insertCell(1).innerHTML = '请核对无误后尽快安排汇款，谢谢！'

      printTable.rows[0].cells[0].colSpan = '12'
      printTable.rows[index+2].cells[0].colSpan = '12'
      printTable.rows[index+3].cells[0].colSpan = '12'
      printTable.rows[index+index1+4].cells[0].colSpan = '12'
      printTable.rows[index+index1+7].cells[0].colSpan = '6'
      printTable.rows[index+index1+7].cells[1].colSpan = '6'
      printTable.rows[index+index1+8].cells[0].colSpan = '6'
      printTable.rows[index+index1+8].cells[1].colSpan = '6'
      printTable.rows[index+index1+9].cells[0].colSpan = '6'
      printTable.rows[index+index1+9].cells[1].colSpan = '6'

      printBody.appendChild(printTable)

      let printHtml = document.getElementById('p').innerHTML
      let wind = window.open("",'newwindow', 'height=500, width=1000, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')
      wind.document.body.innerHTML = printHtml
      let style = document.createElement('style')
      style.type = 'text/css'
      style.innerHTML = resources.printCSS
      wind.document.head.appendChild(style)
      wind.print()
    },

    getSummaries(param){
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        const prop = column.property
        const values = data.map(item => Number(item[prop]))
        if (!values.every(value => isNaN(value))) {
          if (prop == 'number' || prop == 'money' || prop == 'officialReceipts') {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            if (!sums[index]) {
              sums[index] = ''
            }
            let decimal = sums[index].toString().split('.')[1]
            if (decimal && decimal.length > 2) {
              sums[index] = sums[index].toFixed(2)
            }
          }
        }
      })
      this.sums = sums
      return sums
    }
  },
  created(){
    let jxQuarterVal = document.cookie.match(RegExp('jxQuarter' + '=([^;]+)'))
    let jxAgentVal = document.cookie.match(RegExp('jxAgent'+'=([^;]+)'))
    let operatorVal = document.cookie.match(RegExp('jxAgent'+'=([^;]+)'))
    this.jxQuarter = jxQuarterVal ? jxQuarterVal[1] : null
    this.operator = operatorVal ? operatorVal[1] : null
   if(jxAgentVal){
    this.jxAgent = jxAgentVal[1] == 1 ? true : false
   }
    this.inpList = this.getInput()
    // 获取所有客户信息
    getClient({limit:99999}).then(res => {
      // console.log(res)
      if (res.data.code == 200) {
        let list = res.data.data
        list.forEach(e => {
          if(e.stop != 1){
            this.customerList.push({value:e.no,label:e.name})
          }
        })
        if (this.jxAgent) {
          for (const i of this.customerList) {
            if (i.label == this.operator) {
              this.customerNo = i.value
              this.customerName = i.value
              break
            }
          }
        }
      }
    })
    getSystemConfig().then(res => {
      // console.log(res)
      if (res.data.data) {
        this.companyName = res.data.data.companyName
      }
    })
  }
}
</script>